<? include("/inc/header.html") {} ?>
<style>
.row{
	margin-bottom: 10px;
}
</style>
<link rel="stylesheet" href="static/uploadify/uploadify.css" type="text/css"></link>
<script type="text/javascript" src="static/uploadify/jquery.uploadify.min.js"></script>
<script type="text/javascript" src="static/utf8-jsp/ueditor.config.js"></script>
<script type="text/javascript" src="static/utf8-jsp/ueditor.all.js"></script>
<script type="text/javascript" src="static/utf8-jsp/lang/zh-cn/zh-cn.js"></script>
<script type="text/javascript" src="static/utf8-jsp/third-party/video-js/video.js"></script>
<script type="text/javascript" src="static/My97DatePicker/WdatePicker.js"></script>

<div class="col-lg-12" style="overflow: auto;height: 500px;">
	<div class="panel panel">
		<div class="panel-body pan">
			<div class="form-body pal">
				<div class="row">
					<label for="inputUsername" class="col-md-3 control-label">微课名称(不为空,只允许汉字、英文字母、数字及下划线,50字以内)<span
						class='require'>*</span> </label>
					<div class="col-md-9">
							<div class="input-icon">
								<input id="name" type="text" class="form-control" />
							</div>
					</div>
				</div>
				<div class="row">
					<label for="inputUsername" class="col-md-3 control-label">所属课程
						<span class='require'>*</span> </label>
					<div class="col-md-9">
						<div class="input-icon">
							<select class="form-control" id="courseId">
									<option value="">全部</option>
									<!-- <option value="01">高中语文提分攻略</option>
									<option value="02">高中数学提分攻略</option> -->
								</select>
						</div>
					</div>
				</div>
				<div class="row">
					<label for="inputUsername" class="col-md-3 control-label">标签(如多值，用英文分号分割,限制在150个字符内)
						<span class='require'>*</span> </label>
					<div class="col-md-9">
						<div class="input-icon">
							<input id="tag" type="text" class="form-control" />
						</div>
					</div>
				</div>
				<div class="row">
					<label for="inputUsername" class="col-md-3 control-label">类型
						<span class='require'>*</span> </label>
					<div class="col-md-9">
						<div class="input-icon">
							<select class="form-control" id="type">
									<option value="0">视频</option>
									<option value="1">PPT</option>
								</select>
						</div>
					</div>
				</div>
				<div class="row">
					<label for="inputUsername" class="col-md-3 control-label">定价
						<span class='require'>*</span> </label>
						<div class="col-md-9">
							<div class="input-icon">
								<input id="price" type="text" class="form-control" />
							</div>
						</div>
				</div>
				<div class="row">
					<label for="inputUsername" class="col-md-3 control-label">视频地址
						</label>
					<div class="col-md-9">
							<div class="input-icon">
								<input id="videoPath" type="text" class="form-control" />
							</div>
					</div>
				</div>
				<div class="row">
					<label for="inputUsername" class="col-md-3 control-label">PPT地址
						</label>
					<div class="col-md-9">
						<div class="input-group input-group-sm mbs">
								<input id="pptPath" type="text" class="form-control" />
								 <span class="input-group-btn">
								 	<button type="button" data-toggle="dropdown" class="btn btn-blue dropdown-toggle" onclick="shuoming()">PPT课件转换与上传说明</button>
								</span>
						</div>
						</div>
				</div>
				<div class="row">
					<label for="inputUsername" class="col-md-3 control-label">PPT文件上传<span class='require'>*</span></label>
					<div class="col-md-9">
						<div class="input-group input-group-sm mbs">
								<input id="pptFilePath" type="text" placeholder="请点击选择" class="form-control" disabled="true">
								 <span class="input-group-btn">
								 	<button type="button" data-toggle="dropdown" class="btn btn-blue dropdown-toggle" onclick="upFiles()">选择文件</button>
								 	&nbsp;<button type="button" data-toggle="dropdown" class="btn btn-blue dropdown-toggle" onclick="downFiles()">下载文件</button>
								</span>
						</div>
					</div>
				</div>
				<div class="row">
					<label for="inputUsername" class="col-md-3 control-label">PDF资料
						</label>
					<div class="col-md-9">
							<div class="input-icon">
								<input id="pdfPath" type="text" class="form-control" />
							</div>
						</div>
				</div>
				<div class="row">
					<label for="inputUsername" class="col-md-3 control-label">PDF文件上传</label>
					<div class="col-md-9">
						<div class="input-group input-group-sm mbs">
								<input id="pdfFilePath" type="text" placeholder="请点击选择" class="form-control" disabled="true">
								 <span class="input-group-btn">
								 	<button type="button" data-toggle="dropdown" class="btn btn-blue dropdown-toggle" onclick="upFiles1()">选择文件</button>
								</span>
						</div>
					</div>
				</div>
				<div class="row">
					<label for="inputUsername" class="col-md-3 control-label">大纲描述(限制在200字符内)
						<span class='require'>*</span> </label>
					<div class="col-md-9">
						<div class="input-icon">
							<textarea style="width: 100%;" rows="5" id="description"></textarea>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
	<input id="id" type="hidden" value="${id}">
	<textarea id="uploadImage" name="uploadImage" style="display: none;"></textarea>
	<textarea id="uploadImage1" name="uploadImage1" style="display: none;"></textarea>
</div>
<script>
var _editor;
var _editor1;
	$(function() {
		_editor = UE.getEditor('uploadImage');
	    _editor.ready(function (){
	        //设置编辑器不可用(事实上不可以设置不可用...所以注释掉,以观后效)
	        _editor.setDisabled();
	        //隐藏编辑器,因为只使用上传功能
	        _editor.hide();
	        //侦听图片上传
	  	 	_editor.addListener('beforeInsertImage',function(t,arg){
	  	 			/* for(var i=0;i<arg.length;i++){
	  	 				var urlPath = arg[i].src;
	  	 				$("#coverImg").val(urlPath);
						$("#single").html("<a href="+urlPath+" download='w3logo'><img src='"+urlPath+"' width='30' height='30' /></a>");
	  	 			} */
	        });
	        //侦听文件上传
		   	 _editor.addListener('afterUpfile',function(t,arg){
		   	 	for(var i=0;i<arg.length;i++){
	  	 				var urlPath = arg[i].url;
	  	 				$("#pptFilePath").val(urlPath);
	  	 			}
		   	 });
	   });
		_editor1 = UE.getEditor('uploadImage1');
	    _editor1.ready(function (){
	        //设置编辑器不可用(事实上不可以设置不可用...所以注释掉,以观后效)
	        _editor1.setDisabled();
	        //隐藏编辑器,因为只使用上传功能
	        _editor1.hide();
	        //侦听图片上传
	  	 	_editor1.addListener('beforeInsertImage',function(t,arg){
	  	 			/* for(var i=0;i<arg.length;i++){
	  	 				var urlPath = arg[i].src;
	  	 				$("#coverImg").val(urlPath);
						$("#single").html("<a href="+urlPath+" download='w3logo'><img src='"+urlPath+"' width='30' height='30' /></a>");
	  	 			} */
	        });
	        //侦听文件上传
		   	 _editor1.addListener('afterUpfile',function(t,arg){
		   	 	for(var i=0;i<arg.length;i++){
	  	 				var urlPath = arg[i].url;
	  	 				$("#pdfFilePath").val(urlPath);
	  	 			}
		   	 });
	   });
		getCourse();
	});
	function getCourse(){
		$.ajax({
				type : "post",
				url : "./courseListPass.do",
				dataType : "json",
				success : function(data) {
					var html='<option value="">---请选择---</option>';
					for ( var i = 0; i < data.length; i++) {
						html += '<option value="'+data[i].id+'">'+data[i].name+'</option>';
					}
					$("#courseId").html(html);
					init();
				},
				error : function(data) {
					alert("请求失败");
				}
			});
	}
function init(){
	if($("#id").val() != null 
		&& $("#id").val() != ''
		&& $("#id").val() != 'null'
		&& $("#id").val() != 'undefined'
		&&$("#id").val() != undefined){
		$.ajax({
			type : "post",
			url : "./onlineFind.do",
			data : {
				"id" : $("#id").val(),	
			},
			dataType : "json",
			success : function(data) {
				$("#name").val(data[0].name);
				$("#type").val(data[0].type);
				$("#videoPath").val(data[0].videoPath);
				$("#pptPath").val(data[0].pptPath);
				$("#description").val(data[0].description);
				$("#courseId").val(data[0].courseId);
				$("#tag").val(data[0].tag);
				$("#price").val(data[0].price);
				$("#pdfPath").val(data[0].pdfPath);
				
				$("#pptFilePath").val(data[0].pptFilePath);
				$("#pdfFilePath").val(data[0].pdfFilePath);
			},
			error : function(data) {
				alert("请求失败");
			}
		});
	}
	
}	
	
function save(){
	var id;
	if($("#id").val() != null 
		&& $("#id").val() != ''
		&& $("#id").val() != 'null'
		&& $("#id").val() != 'undefined'
		&&$("#id").val() != undefined){
		id=$("#id").val();
	}
	if($("#name").val()==''){
		layer.msg("请输入微课名称");
		return false;
	}
	
	var name=$("#name").val(); //    
    var re =/^[\u4e00-\u9fa5_a-zA-Z0-9]{1,50}$/;
	if (!re.test(name)) {
		layer.msg('微课名称:只允许汉字、英文字母、数字及下划线。50字以内');
		return null;
	}
	
	if($("#courseId").val()==''){
		layer.msg("请选择所属课程");
		return false;
	}
	if($("#tag").val()==''){
		layer.msg("请输入标签 ");
		return false;
	}
	if($("#tag").val().length>150){
		layer.msg("标签:150字以内");
		return false;
	}
	if($("#type").val()==''){
		layer.msg("请选择类型 ");
		return false;
	}
	if($("#price").val()==''){
		layer.msg("请输入定价 ");
		return false;
	}
	var price=$("#price").val(); //    
    var re =/^[0-9]+$/;
	if (!re.test(price)) {
		layer.msg('定价:输入在0-9999之间的整数！');
		return null;
	}
	var num = parseInt(price);
	if(num>9999 || num<0){
		layer.msg('定价:输入在0-9999之间的整数！');
		return null;
	}
	/* if($("#videoPath").val()==''){
		layer.msg("请输入视频地址 ");
		return false;
	}
	if($("#pptPath").val()==''){
		layer.msg("请输入PPT资料地址 ");
		return false;
	}
	if($("#pdfPath").val()==''){
		layer.msg("请输入PDF资料地址 ");
		return false;
	} */
	
	if($("#type").val()=='PPT'&&$("#pptFilePath").val()==''){
		layer.msg("请上传PPT文件");
		return false;
	}
	if($("#description").val()==''){
		layer.msg("请输入大纲描述 ");
		return false;
	}
	if($("#description").val().length>200){
		layer.msg("大纲描述:200字以内 ");
		return false;
	}
	$.ajax({
		type : "post",
		url : "./onlineAddUpdate.do",
		data : {
			"id" : id,
			"name" : $("#name").val(),
			"type" : $("#type").val(),
			"videoPath" : $("#videoPath").val(),
			"pptPath" : $("#pptPath").val(),
			"description" : $("#description").val(),
			"courseId" : $("#courseId").val(),
			"tag" : $("#tag").val(),
			"price" : $("#price").val(),
			"pdfPath" : $("#pdfPath").val(),
			"pptFilePath":$("#pptFilePath").val(),
			"pdfFilePath":$("#pdfFilePath").val()
		},
		dataType : "json",
		success : function(data) {
			if(data[0].result == 'success'){
				var index = parent.layer.getFrameIndex(window.name);
				window.parent.get();
				parent.layer.msg('提交成功');
				parent.layer.close(index);
			}else{
				parent.layer.msg(data[0].msg);
			}
		},
		error : function(data) {
			alert("请求失败");
		}
	});
}

//上传图片
function upImages() {
	var myFiles = _editor.getDialog("insertimage");
  		myFiles.open();
}
 //上传文件
function upFiles() {
	var myFiles = _editor.getDialog("attachment");
   	myFiles.open();
}
 //上传文件
function upFiles1() {
	var myFiles = _editor1.getDialog("attachment");
   	myFiles.open();
}
function downFiles(){
	//pptFilePath
	if($("#pptFilePath").val()){
				window.location.href="./logDownLoad.do?path="+encodeURI($("#pptFilePath").val());
			}
}
function shuoming(){
	var newWin = window.open(); 
	newWin.location =  "./upload/PPT课件转换与上传.pdf";
}
</script>